--[[
	service，检测客户端版本
]]

local filename = "clientversion.lua"
local skynet = require "skynet"
local cluster = require "skynet.cluster"

require "skynet.manager"

local json = require "cjson.safe"
json.encode_sparse_array(true,1,1)

local redisdao = require "redisdao"
local filelog = require "filelog"
local timetool = require "timetool"

local routerbase = require "routerbase"

local ClientVersion = routerbase:new()

local clientverison = nil

function ClientVersion.CMD.get_clientver()
	return clientverison
end

-- 每次gm启动，从redis里面获取客端版本
function ClientVersion.CMD.get_clientver_from_redis()
	local result, result_data = redisdao.query_data(".gmmqredis", "get", "clientver")
	if result_data then
		clientverison = result_data
		--pcall(cluster.send,"gatenode", ".router", "setclientver", clientverison)
	else
		ClientVersion.CMD.renew_clientver()
	end
	return true	
end

-- 更新客户端版本
function ClientVersion.CMD.renew_clientver()
	local result, result_data = redisdao.query_data(".gmmqredis", "get", "clientver")
	if result_data then
		clientverison = result_data
		pcall(cluster.send,"gatenode", ".router", "setclientver", clientverison)
	end
	return true
end

skynet.start(function ()
	ClientVersion:start()
end)
